package com.lwc.cfdns.pojo.bo.monitor;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.lwc.cfdns.pojo.bo.AbstractPageQuery;
import com.lwc.cfdns.pojo.entity.SystemAdmin;
import com.lwc.cfdns.pojo.entity.SystemLogininfor;
import com.lwc.cfdns.utils.StringUtils;
import lombok.Data;

/**
 * 登录记录查询条件
 *
 * @author luwc
 * @title LoginLogBO
 * @description
 * @time 2023/7/25 09:48:31
 * @version: 1.0
 */
@Data
public class LoginLogBO extends AbstractPageQuery<SystemLogininfor> {
    private String ipaddr;
    private String userName;
    private String status;

    private String stime;
    private String etime;

    @Override
    public LambdaQueryWrapper<SystemLogininfor> toQueryWrapper() {
        LambdaQueryWrapper<SystemLogininfor> lambdaQueryWrapper = new LambdaQueryWrapper<>();

        if (StringUtils.isNotEmpty(getIpaddr())) {
            lambdaQueryWrapper.eq(SystemLogininfor::getIpaddr, getIpaddr());
        }
        if (StringUtils.isNotEmpty(getUserName())) {
            lambdaQueryWrapper.like(SystemLogininfor::getUserName, getUserName());
        }
        if (StringUtils.isNotEmpty(getStatus())) {
            lambdaQueryWrapper.eq(SystemLogininfor::getStatus, getStatus());
        }

        // 日期模式
        if (StringUtils.isNotEmpty(this.stime)) {
            lambdaQueryWrapper.ge(SystemLogininfor::getLoginTime, this.stime);
        }
        if (StringUtils.isNotEmpty(this.etime)) {
            lambdaQueryWrapper.le(SystemLogininfor::getLoginTime, this.etime);
        }

        lambdaQueryWrapper.orderByDesc(SystemLogininfor::getId);
        return lambdaQueryWrapper;
    }
}
